<?php

Class Token {
	
	public static function setToken(){
		Session::setSession();
		$token = sha1(uniqid(mt_rand(), true));
		Session::setKey('token', $token);
		Session::setKey('token_time', time());
		return $token;
	}
	
	public static function checkToken() {
		if (Session::isKey('token') && Session::isKey('token_time') && isset($_POST['token'])) {
			if (Session::getKey('token') == $_POST['token']) {
				if (Session::getKey('token_time') >= (time()-(15*60))) {
					Session::unsetKey('token');
					Session::unsetKey('token_time');
				}
				else {
					exit();
				}
			}
			else {
				exit();
			}
		}
		else {
			exit();
		}
	}
	
}

?>